//
//  InvestProgressArcTypeCell.m
//  LingQian
//
//  Created by wtjr on 2018/1/24.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "InvestProgressArcTypeCell.h"
#import "ArcProgressView.h"

@interface InvestProgressArcTypeCell()
@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) ArcProgressView *progressView;
@property (nonatomic, strong) BaseLabel *rateNumberLabel;
@end

@implementation InvestProgressArcTypeCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    static NSString *cellId = @"InvestProgressArcTypeCell";
    InvestProgressArcTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[InvestProgressArcTypeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    return cell;
}

#pragma mark - init

- (void)initData {
    self.backgroundColor = kCOLOR_tableView;
}

- (void)initSubView {
    [self addSubview:self.mainView];
}

- (void)autoLayoutSubviews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0).insets(UIEdgeInsetsMake(10, 20, 10, 20));
    }];
}

#pragma mark - Method


#pragma mark - Interface


#pragma mark - Setter

- (void)setViewModel:(InvestViewModel *)viewModel {
    _viewModel = viewModel;
    
    [self refreshUI];
}

- (void)refreshUI {
    self.rateNumberLabel.textColor = KCOLOR_mainColor;
    [self.rateNumberLabel setViewShadow:[KCOLOR_mainColor colorWithAlphaComponent:0.6] offset:CGSizeMake(0, 0) radius:kUI_ShawRadius/5];
    self.progressView.backLayer.strokeColor = [KCOLOR_mainColor colorWithAlphaComponent:0.2].CGColor;
    self.progressView.roundLayer.strokeColor = [KCOLOR_mainColor colorWithAlphaComponent:0.8].CGColor;
    self.progressView.gradientLayer.colors = @[(id)[KCOLOR_mainColor colorWithAlphaComponent:0.5].CGColor,(id)KCOLOR_mainColor.CGColor];
    self.progressView.percent = 0.5;
}

#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
        _mainView.layer.cornerRadius = kUI_LayerCorner;
        [_mainView setViewShadow:kCOLOR_shadowLight offset:CGSizeMake(0, 0) radius:kUI_ShawRadius];
        
        BaseLabel *bindNameLabel = [BaseLabel new];
        [bindNameLabel setLabelStyle:@"消费贷180121048" textColor:KCOLOR_nornalFont textFont:kFONT_mainFont(12) texrAlignment:NSTextAlignmentLeft];
        [_mainView addSubview:bindNameLabel];
        [bindNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@20);
            make.top.equalTo(@10);
            make.height.equalTo(@14);
        }];
        
        BaseLabel *moneyTagLabel = [BaseLabel new];
        moneyTagLabel.layer.borderColor = kCOLOR_line.CGColor;
        moneyTagLabel.layer.borderWidth = 0.5;
        moneyTagLabel.layer.cornerRadius = 6;
        [moneyTagLabel setLabelStyle:@"融资10万" textColor:KCOLOR_lightFont textFont:kFONT_mainFont(10) texrAlignment:NSTextAlignmentCenter];
        [_mainView addSubview:moneyTagLabel];
        [moneyTagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bindNameLabel.mas_right).offset(10);
            make.centerY.equalTo(bindNameLabel);
            make.width.equalTo(@50);
            make.height.equalTo(@14);
        }];
        
        BaseLabel *dayTagLabel = [BaseLabel new];
        dayTagLabel.layer.borderColor = kCOLOR_line.CGColor;
        dayTagLabel.layer.borderWidth = 0.5;
        dayTagLabel.layer.cornerRadius = 6;
        [dayTagLabel setLabelStyle:@"期限31天" textColor:KCOLOR_lightFont textFont:kFONT_mainFont(10) texrAlignment:NSTextAlignmentCenter];
        [_mainView addSubview:dayTagLabel];
        [dayTagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(moneyTagLabel.mas_right).offset(10);
            make.centerY.equalTo(bindNameLabel);
            make.width.equalTo(@50);
            make.height.equalTo(@14);
        }];
        
        BaseLabel *rateNumberLabel = [BaseLabel new];
        [rateNumberLabel setLabelStyle:@"12.88" textColor:KCOLOR_heavyFont textFont:kFONT_mainBoldFont(30) texrAlignment:NSTextAlignmentCenter];
        self.rateNumberLabel = rateNumberLabel;
        [_mainView addSubview:rateNumberLabel];
        [rateNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bindNameLabel);
            make.centerY.equalTo(@0);
            make.height.equalTo(@30);
        }];
        
        BaseLabel *rateLabel = [BaseLabel new];
        [rateLabel setLabelStyle:@"历史年化" textColor:KCOLOR_lightFont textFont:kFONT_mainFont(8) texrAlignment:NSTextAlignmentCenter];
        [_mainView addSubview:rateLabel];
        [rateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(@-15);
            make.centerX.equalTo(rateNumberLabel);
            make.height.equalTo(@10);
        }];
        
        //添加水球
        ArcProgressView *progressView = [ArcProgressView new];
        progressView.backgroundColor = kCOLOR_white;
        self.progressView = progressView;
        [_mainView addSubview:progressView];
        [progressView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@-20);
            make.centerY.equalTo(rateNumberLabel);
            make.width.equalTo(@60);
            make.height.equalTo(@60);
        }];
        
        BaseLabel *statusLabel = [BaseLabel new];
        statusLabel.alpha = 0.5;
        [statusLabel setLabelStyle:@"" textColor:KCOLOR_heavyFont textFont:kFONT_mainBoldFont(14) texrAlignment:NSTextAlignmentCenter];
        [progressView addSubview:statusLabel];
        [statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(@0);
            make.centerY.equalTo(@0);
            make.height.equalTo(@20);
        }];
    }
    return _mainView;
}
@end
